package edu.luc.etl.jbunit.tl;


/**
 * The formula <code>leaf l</code> specifies that the current label
 * is <code>l</code>.
 */

public class Leaf<T> extends Expr<T> {

  private Predicate<T> predicate;

  /**
   * The constructor of this class assumes that the label provided
   * for this leaf can be safely shared.
   */

  public Leaf(Predicate<T> predicate, boolean v) {
    super(v);
    this.predicate = predicate;
  }

  public Leaf(Predicate<T> predicate) {
    this(predicate, true);
  }
  
  public Leaf(T value, boolean v) {
    this(new EqualityPredicate<T>(value), v);
  }

  public Leaf(T value) {
    this(new EqualityPredicate<T>(value));
  }

  
  public Leaf<T> clone() {
    return (Leaf<T>) super.clone();
  }


  public Predicate<T> getDecider() {
    return predicate;
  }
  
  public void decide(T arg) {
    set(predicate.evaluate(arg));
  }

  void accept(Visitor<T> v) {
    v.visitLeaf(this);
  }
}
